//
//  HMEmoticon.swift
//  Weibo
//
//  Created by 黄亦寒 on 2016/10/6.
//  Copyright © 2016年 HM. All rights reserved.
//

import UIKit
//表情模型
class HMEmoticon: NSObject ,NSCoding{

    //表情描述
    var chs:String?
    //图片名称
    var png:String?
    //表情类型:0代表图片，1代表emoji
    var type:String?
    //emoji字符串(是16进制的)
    var code:String?
    //图片的全路径
    var path:String?
    //图片对应的文件夹名字
    var folderName:String?
    
    //使用yymodel进行归档，需要提供默认的构造函数
    override init() {
        super.init()
    }
    
    //归档与解档
    func encode(with aCoder: NSCoder) {
        aCoder.encode(chs, forKey: "chs")
        aCoder.encode(png, forKey: "png")
        aCoder.encode(type, forKey: "type")
        aCoder.encode(code, forKey: "code")
        aCoder.encode(path, forKey: "path")
        aCoder.encode(folderName, forKey: "folderName")
    }
    
    required init?(coder aDecoder: NSCoder) {
        chs = aDecoder.decodeObject(forKey: "chs") as! String?
        png = aDecoder.decodeObject(forKey: "png") as! String?
        type = aDecoder.decodeObject(forKey: "type") as! String?
        code = aDecoder.decodeObject(forKey: "code") as! String?
        path = aDecoder.decodeObject(forKey: "path") as! String?
        folderName = aDecoder.decodeObject(forKey: "folderName") as! String?
        
        //如果表情模型的类型是图片，需要重写图片的全路径
        if type == "0" {
            let imagePath = HMEmoticonTools.sharedTools.emoticonBundle.path(forResource: folderName, ofType: nil)! + "/" + png!
            path = imagePath
        }
    }
    
}
